x = int(input()) #1735
d = x % 10 #5
a = x // 1000 #1
b1 = x // 100 #17
b = b1 % 10 #7
c1 = x % 100 #35
c = c1 // 10 #3

if len(str(x)) == 4 and x > 0:

    h1 = a * 1000 + b * 100 + c * 10 + d
    h2 = a * 100 + b * 10 + d
    h3 = a * 100 + b * 10 + c
    h4 = c * 10 + d
    h5 = b * 10 + d
    h6 = a * 10 + b
    h7 = a
    h8 = b
    h9 = c
    h10 = d
    
    
    bob = 0
    count = 0
    for i in range(1, h1+1):
        if h1 % i == 0:
            count = count + 1
    if count == 2:
        bob = max(bob, h1)
    
    
    count = 0
    for i in range(1, h2+1):
        if h2 % i == 0:
            count = count + 1
    if count == 2:
        bob = max(bob, h2)
    
    
    count = 0
    for i in range(1, h3+1):
        if h3 % i == 0:
            count = count + 1
    if count == 2:
        bob = max(bob, h3)
    
    

    count = 0
    for i in range(1, h4+1):
        if h4 % i == 0:
            count = count + 1
    if count == 2:
        bob = max(bob, h4) 
    
    
    count = 0
    for i in range(1, h5+1):
        if h5 % i == 0:
            count = count + 1
    if count == 2:
        bob = max(bob, h5)
    
    
    
    count = 0
    for i in range(1, h6+1):
        if h6 % i == 0:
            count = count + 1
    if count == 2:
        bob = max(bob, h6)



    count = 0
    for i in range(1, h7+1):
        if h7 % i == 0:
            count = count + 1
    if count == 2:
        bob = max(bob, h7)

    

    count = 0
    for i in range(1, h8+1):
        if h8 % i == 0:
            count = count + 1
    if count == 2:
        bob = max(bob, h8)



    count = 0
    for i in range(1, h9+1):
        if h9 % i == 0:
            count = count + 1
    if count == 2:
        bob = max(bob, h9)
    
    
    count = 0
    for i in range(1, h10+1):
        if h10 % i == 0:
            count = count + 1
    if count == 2:
        bob = max(bob, h10)

    print(bob)
    
else:
    print(0)
